package com.yiwei.ydd.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.MoneyListsModel;
import com.yiwei.ydd.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class WalletDetailAdapter extends ItemAdapter<MoneyListsModel.DatasBean, WalletDetailAdapter.DefaultHolder> {


    public WalletDetailAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_wallet_detail, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MoneyListsModel.DatasBean item = getItem(position);
        holder.txtTitle.setText(item.desc);
        holder.txtTime.setText(DateTime.toDateTime(Long.valueOf(item.time) * 1000));
        String sign = "";
        if (item.type.equals("1")) {
            sign = "+";
        } else {
            sign = "-";
        }
        holder.txtMoney.setText(sign + item.money);

        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick(item.order_type, item.order_no);
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String order_type, String order_no);
    }
}
